package cbbx_sm.probabilistic_model;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map.Entry;

import cbbx_sm.utils.Timestamp;

/**
 * This class represent a prediction on the future state of the system.
 * For now, it has only probability about clusters containing something
 * at next time, but in the future we can think about more complex or
 * different kind of prediction. E.g., a prediction could be a system
 * state supposed to be the next, or something more articulated.
 * 
 * @author Alessio Della Motta - University of California, Irvine
 *
 */
public class Prediction implements Serializable {
	private static final long serialVersionUID = 1L;
	
	private Timestamp timestamp;
	private HashMap<Cluster, Double> clusterProbabilities = new HashMap<Cluster, Double>();

	public double getClusterProbability(Cluster cluster){
		return clusterProbabilities.get(cluster);
	}
	
	
	//Getters and Setters
	
	public HashMap<Cluster, Double> getClusterProbabilities() {
		return clusterProbabilities;
	}
	
	public void setProbabilities(HashMap<Cluster, Double> clusterProbabilities) {
		this.clusterProbabilities = clusterProbabilities;
	}


	public void setTimestamp(Timestamp timestamp) {
		this.timestamp = timestamp;
	}

	public Timestamp getTimestamp() {
		return timestamp;
	}
	
	@Override
	public String toString(){
		StringBuffer str = new StringBuffer();
		str.append("(");
		for (Entry<Cluster, Double> e : clusterProbabilities.entrySet()) {
			str.append(String.format("%.2f, ", e.getValue()));
		}
		str.append(")%n");
		return str.toString();
	}
	
	@Override
	public boolean equals(Object obj){	
		Prediction prediction = (Prediction) obj;
		
		for (Cluster cluster : this.clusterProbabilities.keySet()){
			double thisProb = this.getClusterProbability(cluster);
			double otherProb = prediction.getClusterProbability(cluster);
			if (thisProb != otherProb) return false;
		}
		
		return true;
	}
}
